package de.koller.cell;

import de.koller.aframe.gl.IARoot;
import de.koller.aframe.util.ALoop;
import de.koller.aframe.util.node.NodeA;
import de.koller.aframe.util.thread.ICommand;
import de.koller.cell.client.CClient;
import de.koller.cell.engine.CEngine;
import de.koller.oceanFramework.tree.Child;
import java.util.Random;

public class CRoot extends NodeA implements IARoot {
	public static final Random RND = new Random();
	
	private final ALoop loop = new ALoop( this );
	@Child public final CEngine engine = new CEngine();
	@Child public final CClient client = new CClient();

	public static void startGame() {
		CRoot root = new CRoot();
		root.start();
	}

	public void start() {
		loop.begin();
	}
	
	@Override
	protected void init() {
		super.init();
		
		this.setIgnoreChildRender( true );
	}

	@Override
	public void postChildUpdate( int elapsedTime ) {
		super.postChildUpdate( elapsedTime );
		
		client.display.render();
	}
	
	public void stopRoot() {
		loop.stop();
	}

	public void call( ICommand command ) {
		loop.thread.call( command );
	}

	@Override
	public long getSystemTime() {
		return System.currentTimeMillis();
	}
	
	
}
